﻿using System;
using l1cs.server.datatables;
using l1cs.server.model.Instance;
using l1cs.server.templates;

namespace l1cs.server.serverpackets
{
    public class S_Board : ServerBasePacket
    {
        private static Logger _log = Logger.getLogger( typeof( S_Board ).FullName );

        private byte[] _byte = null;

        public S_Board( L1NpcInstance board )
        {
            buildPacket( board, 0 );
        }

        public S_Board( L1NpcInstance board, int number )
        {
            buildPacket( board, number );
        }

        private void buildPacket( L1NpcInstance board, int number )
        {
            L1Board[] boards = BoardTable.getInstance().getViewList( number );
            writeC( Opcodes.S_OPCODE_BOARD );
            writeD( board.getId() );
            writeC( 0xFF ); // ?
            writeC( 0xFF ); // ?
            writeC( 0xFF ); // ?
            writeC( 0x7F ); // ?
            writeH( boards.Length );
            writeH( 300 );
            foreach ( L1Board l1board in boards )
            {
                writeD( l1board.id );
                writeS( l1board.name );
                writeS( l1board.date );
                writeS( l1board.content );
            }
        }

        override
        public byte[] getContent()
        {
            if ( _byte == null )
            {
                _byte = getBytes();
            }
            return _byte;
        }

        override
        public String getType()
        {
            return "[S] S_Board";
        }
    }
}
